Menu

how use this code?

Anonymous
2012-10-03
2013-07-24
  • Anonymous

    Anonymous - 2012-10-03

    Marat hi!

    Can you give examples of the use of this code?
    I understand that there are unit tests, but I do not understand how to define the message and how to organize the parse of messages?
    If there was an example of how you do it, it would be useful.
    I would be extremely grateful.

    Max

     
  • Marat

    Marat - 2012-10-03

    Max, the question is pertinent.
    I have a project that was implemented this code. I will try to put an example of use in a small project.

     
  • Marat

    Marat - 2013-04-13

    Hi Benoit!

    Version 1.1 contains a sample as a project and as a unit test project.

    Sincerely,
    Marat

     
  • Benoit Dupraz

    Benoit Dupraz - 2013-07-03

    Hi,

    thank you for the release. The example has been very helpful to me. I still have a question. I'm now using your project but I want to define a "proto file" with a message containing a boolean.
    And I have problem with the procedure TPersonReader.Load (to refer to your example, I add a boolean to the message).

    I write this, but I have an error invalidWireType.

    begin
    tag := FBuffer.readTag;
    while tag <> 0 do begin
    wireType := getTagWireType(tag);
    fieldNumber := getTagFieldNumber(tag);
    case fieldNumber of
    TBool.ft_Value:
    begin
    Assert(wireType = WIRETYPE_VARINT);
    Bool.Value := FBuffer.readBoolean;
    end;
    else
    FBuffer.skipField(tag);
    end;
    tag := FBuffer.readTag;
    end;
    end;

    Edit : For me the problem comes from the LoadFromfile or SaveToFile methods.
    Instead I use a stream and it seems to work fine. But I have not the time to investigate more and correct the issue.

    Regards,

    Benoit

     

    Last edit: Benoit Dupraz 2013-07-04
  • Marat

    Marat - 2013-07-24

    Hi, Benoit

    I think the right not to extend the library, it is quite matches the code which is in the libraries in other languages.

    I would use a boolean to integer conversion and vice versa.
    1. Convert boolean to integer.
    intValue := Ord (boolValue);
    Ord (False) = 0
    Ord (True) = 1;
    Write the converted integer value to Proto.

    1. Then read the previously recorded integer value from Proto.
      For convert integer to boolean use
      boolValue := intValue <> 0

    The same action can be done with any enumerated data types.

    TEnumType = (etFirst, etSecond, .., etLast)
    var enumValue: TEnumType;

    enumValue := TEnumType(intValue)

    Boolean is also an enumerated type.

    In the example contain code with an enumerated type.

        if Phone.FTyp <> ptHOME then
          PhonesBuffer.writeInt32(TPhoneNumber.ft_Typ, Ord(Phone.FTyp));
    
     

Anonymous
Anonymous

Add attachments
Cancel