Ravn::

Tak module

Namespace for TAK protobuf messages, loosely described at:

github.com/deptofdefense/AndroidTacticalAssaultKit-CIV/blob/master/commoncommo/core/impl/protobuf/protocol.txt

Within that directory also lives the .proto description files – ensure you’re using a “protoc” binary >= 0.27 to generate the descriptors found below.

This currently is only a parser/generator for protobuf formatted TAK messages, and a landing spot for future TAK functionality.

Ravn::Tak.parse( binary_packet ) #=> (ruby hash)

Constants

DESCRIPTORS

Namespaces and their descriptors. Order matters! Some of these have interdependencies.

MAGIC_BYTE

TAK identification bit.

PROTOBUF_POOL

The protobuf description parser.

Public Instance Methods

parse( raw )

Given a raw binary blob (presumably from the network), decode and return a parsed TakMessage structure. If unparsable, raises a Ravn::Tak::ParseError.

# File lib/ravn/tak.rb, line 252
def parse( raw )
        header = raw.byteslice( 0..2 )
        body   = raw.byteslice( 3..-1 )

        m1, type, m2 = *header.bytes
        unless m1 == MAGIC_BYTE && m2 == MAGIC_BYTE
                raise ParseError, "This doesn't appear to be a TAK packet. (%p %p)" % [ m1, m2 ]
        end

        case type
        when 0
                return self.parse_xml( body )
        when 1
                return self.parse_protobuf( body )
        else
                raise ParseError, "Unknown message type: (%p)" % [ type ]
        end
end
parse_protobuf( message )

Return a ruby object from a TakMessage protobuf message.

# File lib/ravn/tak.rb, line 279
def parse_protobuf( message )
        return TakMessage.decode( message )
rescue Google::Protobuf::ParseError => err
        raise ParseError, err.message
end
parse_xml( message )

Return a ruby object from an XML-style TAK message.

# File lib/ravn/tak.rb, line 273
def parse_xml( message )
        raise NotImplementedError, "XML bodies currently are unsupported."
end