eclipse-leshan / leshan

Java Library for LWM2M
https://www.eclipse.org/leshan/
BSD 3-Clause "New" or "Revised" License
652 stars 407 forks source link

About TLV encoding object instance When send lwm2m put-write request #660

Closed chen0411 closed 5 years ago

chen0411 commented 5 years ago

I have problem, ask for help. Thanks! Scenario as follows, when I want to modify the value of lifetime (path: /1/1/1) and minimum period( path:/1/1/2),will send a put-write request, the uri path of request is /1/1, and payload data is a object instance, and the content-format is set to TLV. And find that type of indentifier are both 0b11. I think it is caused by the following handler function。 /leshan-core/src/main/java/org/eclipse/leshan/core/node/codec/tlv/LwM2mNodeTlvEncoder.java

        public void visit(LwM2mObjectInstance instance) {
            LOG.trace("Encoding object instance {} into TLV", instance);

            Tlv[] tlvs;
            if (path.isObjectInstance() || instance.getId() == LwM2mObjectInstance.UNDEFINED) {
                // the instanceId is part of the request path or is undefined
                // so the instance TLV layer is not needed.
                // encoded as an array of resource TLVs
                tlvs = encodeResources(instance.getResources().values(),
                        new LwM2mPath(path.getObjectId(), instance.getId()));
            } else {
                // encoded as an instance TLV
                Tlv[] resources = encodeResources(instance.getResources().values(),
                        new LwM2mPath(path.getObjectId(), instance.getId()));
                tlvs = new Tlv[] { new Tlv(TlvType.OBJECT_INSTANCE, resources, null, instance.getId()) };
            }

            try {
                out.write(TlvEncoder.encode(tlvs).array());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

But this is described about write request on page 50 of the protocol document (OMA-TS-LightweightM2M_Core-V1_1-20180710-A.pdf)

If no Resource ID is indicated, the Resource Instance ID MUST NOT be indicated , then the value included payload is an Object Instance containing the Resource values.

I think this approach conflicts with the document ,but I don't know why.

sbernard31 commented 5 years ago

I see you reference the v1.1 version, keep in mind that Leshan currently aims the v1.0.x. (see https://github.com/eclipse/leshan/issues/563 for more details about Leshan and v1.1)

Anyway, there is maybe an ambiguity in the specification. (And the ambiguity seems to concern both version of the specification), but for me Leshan's behavior is OK.

Look at this to get more details : https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/452

chen0411 commented 5 years ago

@sbernard31 Thank you for your patient reply.

sbernard31 commented 5 years ago

OpenMobileAlliance/OMA_LwM2M_for_Developers#452 confirms that Leshan behavior sounds OK.

So I close this issue.